package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.sys.SysRoleDto;
import com.atguigu.spzx.model.entity.sys.SysRole;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2023/12/27
 * description：
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public PageInfo<SysRole> getRoleList(SysRoleDto sysRoleDto) {
        //获取参数
        Integer pageNum = sysRoleDto.getPageNum();
        Integer pageSize = sysRoleDto.getPageSize();
        String keywords = sysRoleDto.getKeywords();
        //设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        //数据库查询
        List<SysRole> roleList = sysRoleMapper.getRoleList(keywords);
        PageInfo<SysRole> pageInfo = new PageInfo<>(roleList);
        return pageInfo;
    }

    @Override
    public void deleteById(Long id) {
        sysRoleMapper.deleteById(id);
    }

    @Override
    public void save(SysRole sysRole) {
        sysRoleMapper.save(sysRole);
    }

    @Override
    public void updateRole(SysRole sysRole) {
        sysRoleMapper.updateRole(sysRole);
    }
}
